

#ifndef _THREAD_H_
#define _THREAD_H_

#include "noncopyable.hpp"
#include <atomic>
#include <functional>
#include <memory>
#include <thread>
#include <string>

namespace zephyr {

class Thread : noncopyable {
public:
    using ThreadFuc = std::function<void()>;
    explicit Thread(ThreadFuc, const std::string &name = std::string());
    ~Thread();
    void start();
    void join();
    bool started() {
        return m_started;
    }

    pid_t tid() const {
        return m_tid;
    }

    const std::string &name() const {
        return m_name;
    }

    static int numCreated() {
        return m_numCreated;
    }
private:
    void setDefauleName();
    bool m_started;
    bool m_joined;
    std::shared_ptr<std::thread> m_thread;
    pid_t m_tid;
    ThreadFuc m_func;
    std::string m_name;
    static std::atomic_int m_numCreated;
};

}

#endif // _THREAD_H_